1. /* scostrm.cpp by K.Tsuru */
  2. // function ID = 902
  3. /**************************
  4. SComplex class
  5. It provides the output.
  6. **************************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. // static objects of SComplex class
  11. int SComplex::scLineFormat = SComplex::BracketFMT; // set by BRACKET | MID_CR| END_CR
  12. long SComplex::ioCount = 0;
  13. void SComplex::SetFormat(int fmt) {
  14. scLineFormat = fmt;
  15. }
  16. ostream& operator<<(ostream& os, const SComplex& sc) {
  17. sc.ioCount = 0;
  18. SDouble sd;
  19. long p = 0;
  20. if(sc.scLineFormat & sc.BracketFMT){
  21. os << '('; p++;
  22. os << sc.Real(); p += sd.ioCount; sd.ioCount = 0;
  23. if(sc.scLineFormat & sc.MID_CR) os << ',' << endl; // ",\n" two characters
  24. else os << ", ";
  25. p += 2;
  26. os << sc.Imag(); p += sd.ioCount; sd.ioCount = 0;
  27. os << ')'; p++;
  28. if(sc.scLineFormat & sc.END_CR) { os << endl; p++; }
  29. sc.ioCount = p;
  30. return os;
  31. }
  32. SDouble im(sc.Imag());
  33. int imSign = im.Sign(902);
  34. if(imSign < 0) im.ChangeSign(902); // im = -im > 0
  35. os << sc.Real(); p = sd.ioCount;
  36. if(sc.scLineFormat & sc.MID_CR){ os <<endl; p++; }
  37. os.flush();
  38. if(imSign < 0){
  39. os << "-i*"; p += 3;
  40. os << im; p += sd.ioCount;
  41. } else if(imSign > 0){
  42. os << "+i*"; p += 3;
  43. os << sc.Imag(); p += sd.ioCount;
  44. } else {
  45. os << "+i*0.0"; p += 6;
  46. }
  47. if(sc.scLineFormat & sc.END_CR){ os << endl; p++; }
  48. return os;
  49. }

scostrm.cpp : last modifiled at 2017/06/14 20:43:01(1,388 bytes)
created at 2017/10/06 15:21:28
The creation time of this html file is 2017/10/06 15:27:09 (Fri Oct 06 15:27:09 2017).